﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;

public partial class MemLogin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void login_in_sumbit_Click(object sender, EventArgs e)
    {
        #region 基础判断

        if (txtMobile.Text.Trim() == string.Empty)
        {
            errorTip.Text = "登录名或密码错误";
            return;
        }
        if (txtPassword.Text.Trim() == string.Empty)
        {
            errorTip.Text = "登录名或密码错误";
            return;
        }
        if (Request.Cookies["CheckCode"].Value != TxtCode.Text.ToUpper())
        {
            errorTip.Text = "验证码错误！";
            return;
        }
        int status = 0;
        DataTable dtConfig = BLL.Config.GetTableConfig();
        status = Convert.ToInt32(dtConfig.Rows[0]["WebClose"]);
        if (status == 1)
        {
            CommenMethod.GetJavaScript("网站正在维护，暂时无法登陆！");
            return;
        }
        if (!BLL.User.IsExistMember(txtMobile.Text.Trim(), CommenMethod.md5(txtPassword.Text.Trim(), 32)))
        {
            errorTip.Text = "登录名或密码错误";
            return;
        }
        if (BLL.User.CheckMemberIsFreeState(txtMobile.Text.Trim()))
        {
            CommenMethod.GetJavaScript("该账号已冻结，请联系管理员！");
            return;
        }
        DataTable dtUserInfo = BLL.User.GetReferee(txtMobile.Text);
        //if (Int32.Parse(dtUserInfo.Rows[0]["FrozenState"].ToString()) == 0)
        //{
        //    CommenMethod.GetJavaScript("账号还未激活，暂时无法登录系统!");
        //    return;
        //}
        if (Int32.Parse(dtUserInfo.Rows[0]["FrozenState"].ToString()) == 0)
        {
            DateTime d1 = Convert.ToDateTime(dtUserInfo.Rows[0]["RegTime"].ToString());
            DateTime d2 = Convert.ToDateTime(DateTime.Now.ToString());
            TimeSpan d3 = d2.Subtract(d1);
            string Text = "相差:" + d3.Days.ToString() + "天" + d3.Hours.ToString() + "小时" + d3.Minutes.ToString() + "分钟" + d3.Seconds.ToString() + "秒";

            if (2 <= d3.Days)
            {
                CommenMethod.GetJavaScript("账号注册已超过48小时未激活，无法登录系统!");
                return;
            }

        }
        #endregion

        // when username and password is correct 
        Session.Add("UserId", txtMobile.Text.Trim());
        Page.RegisterStartupScript("ggg1", " <script>window.parent.location.href='/Member/Default.aspx'; </script>");
        //Response.Redirect("~/Member/Default.aspx", true);
    }

}